home *** CD-ROM | disk | FTP | other *** search
/ Aminet 24 / Aminet 24 (1998)(GTI - Schatztruhe)[!][Apr 1998].iso / Aminet / dev / c / AmiVoGL_MDEV.lha / examples / world.c.bak < prev    next >
Text File  |  1997-08-16  |  3KB  |  169 lines

  1. #include <stdio.h>
  2.  
  3. #ifdef SGI
  4. #include "gl.h"
  5. #include "device.h"
  6. #include "hershey.h"
  7. #else
  8. #include "vogl.h"
  9. #include "vodevice.h"
  10. #endif
  11.  
  12. #ifndef PI
  13. #define PI    3.1415926535
  14. #endif
  15.  
  16. #ifndef TC
  17. #include <math.h>
  18. #else
  19. extern double    sin(), cos();
  20. #endif
  21.  
  22. #define RADIUS    10.0
  23. #define    SPHERE    1L
  24.  
  25. /* ---------------------------------------------------------------------
  26.  * Prototypes:
  27.  */
  28. int main(void);                                        /* world.c         */
  29. void showroundtext(char *);                            /* world.c         */
  30. void makesphere(void);                                 /* world.c         */
  31.  
  32. /* ---------------------------------------------------------------------
  33.  * Source:
  34.  */
  35.  
  36. /*
  37.  * most of the things in this program have been done before but it has
  38.  * a certain novelty value.
  39.  */
  40. int main(void)
  41. {
  42.     int    i;
  43.     short    val;
  44.     float    r, z, a;
  45.  
  46.     winopen("world");
  47.  
  48.     qdevice(KEYBD);
  49.     unqdevice(INPUTCHANGE);
  50.  
  51.     hfont("futura.m");
  52.  
  53.     perspective(800, 1.0, 0.001, 50.0);
  54.     lookat(13.0, 13.0, 8.0, 0.0, 0.0, 0.0, 0);
  55.  
  56.     color(BLACK);
  57.     clear();
  58.  
  59.     makesphere();
  60.  
  61.     /*
  62.      * draw the main one in cyan
  63.      */
  64.     color(CYAN);
  65.  
  66.     callobj(SPHERE);
  67.  
  68.     /*
  69.      * draw a smaller one outside the main one in white
  70.      */
  71.     color(WHITE);
  72.  
  73.     pushmatrix();
  74.         translate(0.0, -1.4 * RADIUS, 1.4 * RADIUS);
  75.         scale(0.3, 0.3, 0.3);
  76.         callobj(SPHERE);
  77.     popmatrix();
  78.  
  79.     /*
  80.      * scale the text
  81.      */
  82.     hboxfit(2.0 * PI * RADIUS, 0.25 * RADIUS, 31);
  83.  
  84.     /*
  85.      * now write the text in rings around the main sphere
  86.      */
  87.  
  88.     color(GREEN);
  89.     showroundtext("Around the world in eighty days ");
  90.  
  91.     color(BLUE);
  92.     /*
  93.      * note: that software text is rotated here as
  94.      * anything else would be whether you use textang
  95.      * or rotate depends on what you are trying to do.
  96.      * Experience is the best teacher here.
  97.      */
  98.     rotate(900, 'x');
  99.     showroundtext("Around the world in eighty days ");
  100.  
  101.     color(RED);
  102.     rotate(900, 'z');
  103.       showroundtext("Around the world in eighty days ");
  104.  
  105.     qread(&val);
  106.  
  107.     gexit();
  108. }
  109.  
  110. /*
  111.  * showroundtext
  112.  *
  113.  *    draw string str wrapped around a circle in 3d
  114.  */
  115. void showroundtext(char *str)
  116. {
  117.     int    i, inc;
  118.  
  119.     inc = 3600 / strlen(str);
  120.  
  121.     for (i = 0; i < 3600; i += inc) {
  122.         pushmatrix();
  123.             /*
  124.              * find the spot on the edge of the sphere
  125.              * by making it (0, 0, 0) in world coordinates
  126.              */
  127.             rotate(i, 'y');
  128.             translate(0.0, 0.0, RADIUS);
  129.  
  130.             move(0.0, 0.0, 0.0);
  131.  
  132.             hdrawchar(*str++);
  133.         popmatrix();
  134.     }
  135. }
  136.  
  137. /*
  138.  * makesphere
  139.  *
  140.  *    create the sphere object
  141.  */
  142. void makesphere(void)
  143. {
  144.     float    i, r, z, a;
  145.  
  146.     makeobj(SPHERE);
  147.  
  148.         for (i = 0; i < 180; i += 20) {
  149.             pushmatrix();
  150.                 rotate((int)i * 10, 'y');
  151.                 circ(0.0, 0.0, RADIUS);
  152.             popmatrix();
  153.         }
  154.         
  155.         pushmatrix();
  156.             rotate(900, 'x');
  157.             for (a = -90.0; a < 90.0; a += 20.0) {
  158.                 r = RADIUS * cos((double)a * PI / 180.0);
  159.                 z = RADIUS * sin((double)a * PI / 180.0);
  160.                 pushmatrix();
  161.                     translate(0.0, 0.0, -z);
  162.                     circ(0.0, 0.0, r);
  163.                 popmatrix();    
  164.             }
  165.         popmatrix();
  166.  
  167.     closeobj();
  168. }
  169.